<style lang="less" scoped>
@import "@/styles/table-common.less";
.btn-box {
  // padding: 10px 12px 10px 0;
  height: 32px;
  display: flex;
  align-items: center;
  span {
    margin-left: 15px;
  }
}
.content {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 40px;
  /deep/.c-card {
    width: 380px;
    margin-right: 25px;
    .num {
      font-size: 40px;
      margin-bottom: 20px;
    }
    .card-footer {
      display: flex;
      justify-content: space-between;
      border-top: 1px solid #e8eaec;
      padding-top: 10px;
    }
  }
}
</style> 
<template>
  <div class="search">
    <div class="content">
      <Card class="c-card">
        <p slot="title">平台储值金额</p>
        <Tag color="blue" slot="extra">月</Tag>
        <div class="num">￥{{ moneyObj.rechargeMoney }}</div>
      </Card>
      <Card class="c-card">
        <p slot="title">剩余金额</p>
        <Tag color="blue" slot="extra">月</Tag>
        <div class="num">￥{{ moneyObj.remainMoney }}</div>
      </Card>
      <Card class="c-card">
        <p slot="title">消费金额</p>
        <Tag color="blue" slot="extra">月</Tag>
        <div class="num">￥{{ moneyObj.payMoney }}</div>
      </Card>
    </div>

    <Card>
      <!-- <Row class="operation">
        <Button @click="add" type="primary" icon="md-add">添加</Button>
      </Row> -->
      <Form ref="searchForm" :model="searchForm" inline :label-width="100">
        <Row v-show="openSearch" @keydown.enter.native="handleSearch">
          <FormItem label="企业：">
            <Select
              v-model="searchForm.companyId"
              transfer
              placeholder="请选择"
              style="width: 200px"
            >
              <Option
                v-for="item in companyList"
                :key="item.id"
                :value="item.id"
                >{{ item.companyName }}</Option
              >
            </Select>
          </FormItem>
          <FormItem label="结算状态：">
            <Select
              v-model="searchForm.status"
              transfer
              placeholder="请选择"
              style="width: 200px"
            >
              <Option value="0">待结算</Option>
              <Option value="1">有尾款</Option>
              <Option value="2">已结算</Option>
            </Select>
          </FormItem>
          <FormItem label="订单发起时间">
            <DatePicker
              :options="options"
              v-model="selectDate"
              type="daterange"
              format="yyyy-MM-dd"
              clearable
              @on-change="selectDateRange"
              placeholder="选择起始时间"
              style="width: 200px"
            ></DatePicker>
          </FormItem>

          <FormItem style="margin-left: -35px" class="br">
            <Button @click="handleSearch" type="primary" icon="ios-search"
              >搜索</Button
            >
            <Button @click="handleReset">重置</Button>
          </FormItem>
        </Row>
      </Form>

      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="data"
        sortable="custom"
        ref="table"
      >
        <!-- <template slot-scope="{ row }" slot="print">{{ row.print.serialNo }}</template> -->
      </Table>
      <Row type="flex" justify="end" class="page">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>

    <Modal v-model="modal" title="详情" @on-ok="ok" @on-cancel="cancel">
      <div class="detail-modal">
        <Form
          ref="form"
          :model="formSet"
          label-position="top"
          :rules="formSetRule"
        >
          <Row :gutter="32">
            <Col span="24">
              <FormItem
                label="纳入金额：（可输入最大值为当前未付金额）"
                prop="num"
              >
                <Input v-model="formSet.num" placeholder="请填写数字" />
              </FormItem>
            </Col>
          </Row>
        </Form>
      </div>
      <div slot="footer">
        <Button
          type="primary"
          size="large"
          :loading="submitLoading"
          @click="submit"
          >保存</Button
        >
        <Button size="large" @click="cancel">取消</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  getScMonthSettleByCondition,
  scMonthSettleSettle,
  getscMonthSettleStatistic,
  getScCompanyAllCompany,
} from "@/api/index";

import { shortcuts } from "@/libs/shortcuts";
export default {
  name: "user-manage",
  components: {},
  data() {
    return {
      message: "",
      height: 510,
      showUser: false,
      showType: "0",
      loading: true,
      selectDate: "",
      openSearch: true,
      idenList: [], //角色状态
      options: {
        shortcuts: shortcuts,
      },
      orderTypeList: [
        { id: "0", title: "已取消" },
        { id: "1", title: "已完成" },
      ],
      formSetRule: {
        num: [{ required: true, message: "请输入纳入金额", trigger: "blur" }],
      },
      searchForm: {
        pageNumber: 1,
        pageSize: "10",
        sort: "createTime",
        order: "desc",
      },
      columns: [
        {
          title: "月份",
          key: "settleDate",
          minWidth: 120,
          align: "center",
          fixed: "left",
          render: (h, params) => {
            let nodeTxt = "";
            if (params.row.settleDate) {
              let date = params.row.settleDate.split("-");
              nodeTxt = date[0] + "年" + date[1] + "月";
            }
            return h("span", [nodeTxt]);
          },
        },
        {
          title: "企业名称",
          key: "companyName",
          width: 180,
          align: "center",
          fixed: "left",
        },
        {
          title: "企业性质",
          key: "companyType",
          width: 140,
          align: "center",
        },
        {
          title: "云打印订单量",
          key: "printOrderTotal",
          width: 140,
          align: "center",
        },
        {
          title: "企业云打印积分消耗",
          key: "printIntegral",
          width: 200,
          align: "center",
        },
        {
          title: "当前所剩企业云打印积分",
          key: "remainPrintIntegral",
          width: 200,
          align: "center",
        },
        {
          title: "共享会议室订单量",
          key: "meetOrderTotal",
          width: 160,
          align: "center",
        },
        {
          title: "企业会议室积分消耗",
          key: "meetIntegral",
          width: 200,
          align: "center",
        },
        {
          title: "当前所剩企业会议室积分",
          key: "remainMeetIntegral",
          width: 200,
          align: "center",
        },
        {
          title: "最终结算",
          key: "settleSumPrice",
          width: 120,
          align: "center",
        },
        {
          title: "实付金额",
          key: "paySumPrice",
          width: 120,
          align: "center",
        },
        {
          title: "未付金额",
          key: "useIntegralType",
          width: 120,
          align: "center",
          render: (h, params) => {
            let txt = params.row.settleSumPrice - params.row.paySumPrice;
            return h("span", [txt]);
          },
        },
        {
          title: "结算状态",
          key: "status",
          width: 100,
          align: "center",
          render: (h, params) => {
            let txt = "";
            if (params.row.status == 0) {
              txt = "待结算";
            } else if (params.row.status == 1) {
              txt = "有尾款";
            } else if (params.row.status == 2) {
              txt = "已结算";
            }
            return h("span", [txt]);
          },
        },
        {
          title: "操作",
          key: "createTime",
          width: 100,
          align: "center",
          fixed: "right",
          render: (h, params) => {
            let enableOrDisable = "";
            enableOrDisable = h(
              "a",
              {
                on: {
                  click: () => {
                    this.modal = true;
                    this.detailData = params.row;
                  },
                },
              },
              "处理"
            );
            return h("div", [enableOrDisable]);
          },
        },
      ],
      modal: false,
      formSet: {},
      data: [],
      detailData: [],
      companyList: [],
      moneyObj: {},
    };
  },
  methods: {
    init() {
      this.getDataList();
      this.getScCompanyAllCompanyData();
      this.getscMonthSettleStatisticData();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order == "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
      // 多条件搜索用户列表
      this.loading = true;
      getScMonthSettleByCondition(this.searchForm).then((res) => {
        this.loading = false;
        if (res.success) {
          this.data = res.result.content;
          this.total = res.result.totalElements;
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        }
      });
    },
    getScCompanyAllCompanyData() {
      getScCompanyAllCompany().then((res) => {
        if (res.success) {
          this.companyList = res.result;
        }
      });
    },
    getscMonthSettleStatisticData() {
      getscMonthSettleStatistic().then((res) => {
        if (res.success) {
          this.moneyObj = res.result;
        }
      });
    },
    add() {
      this.showType = "2";
      this.showUser = true;
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // return
      this.getDataList();
    },
    handleReset() {
      this.selectDate = "";
      this.searchForm.startDate = "";
      this.searchForm.endDate = "";
      this.searchForm.status = "";
      this.searchForm.companyId = "";
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.getDataList();
    },
    enable(v) {
      this.$Modal.confirm({
        title: "确认启用",
        content: "您确认要启用用户 " + v.title + " ?",
        loading: true,
        onOk: () => {
          enableUser(v.id).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.$Message.success("操作成功");
              this.getDataList();
            }
          });
        },
      });
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (
            this.formSet.num >
            this.detailData.settleSumPrice - this.detailData.paySumPrice
          ) {
            this.$Message.warning("输入金额大于当前未付金额");
            return;
          }
          scMonthSettleSettle({
            ...this.formSet,
            id: this.detailData.id,
          }).then((res) => {
            if (res.success) {
              this.formSet.num = "";
              this.$Message.success("操作成功");
              this.modal = false;
              this.getDataList();
            }
          });
        }
      });
    },
    cancel() {
      this.modal = false;
      this.formSet.num = "";
    },
  },
  created() {},
  mounted() {
    // 计算高度
    this.height = Number(document.documentElement.clientHeight - 230);
    this.init();
  },
};
</script>